<!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
<html>
<head>

	<meta http-equiv="X-UA-Compatible" content="IE=edge" />

	<script type="text/javascript" src="../../loader.js"></script>
	<script>
	require.config({
		baseUrl: '../../../',
		catchError: true
	});

	(function() {
		var isFirstMessage = true;
		var beforeReadyMessages = [];

		var loadCode = function(moduleId) {
			require([moduleId], function(ws) {
				var workerServer = ws.create(function (msg) {
					window.parent.postMessage(msg, '*');
				});

				var readyListener = function (ev) {
					workerServer.onmessage(ev.data);
				};
				if (window.attachEvent) {
					window.detachEvent('onmessage', beforeReadyListener);
					window.attachEvent('onmessage', readyListener);
				} else {
					window.onmessage = readyListener;
				}
				while(beforeReadyMessages.length > 0) {
					readyListener({ data: beforeReadyMessages.shift() });
				}
			});
		};

		var beforeReadyListener = function (message) {
			if (!isFirstMessage) {
				beforeReadyMessages.push(message.data);
				return;
			}

			isFirstMessage = false;
			loadCode(message.data);
		};

		if (window.attachEvent) {
			window.attachEvent('onmessage', beforeReadyListener);
		} else {
			window.onmessage = beforeReadyListener;
		}
	})();
	</script>
</head>
<body>
	<div>compatibility worker iframe</div>
</body>
</html>
